package com.sky.web.admin;

import com.sky.exception.BusinessException;
import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.net.BindException;

@RestController
@RequestMapping("/admin/common/upload")
public class CommonController {
    @Autowired
    private AliOssUtil aliOssUtil;

    @PostMapping
    public Result upload( MultipartFile file) throws IOException {
        if(file.isEmpty()){
            throw new BusinessException("图片上传失败");
        }
        return Result.success(aliOssUtil.upload(file.getOriginalFilename(),file.getInputStream()));
    }
}
